<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Data-Table 表格</title>
    <link rel="stylesheet" href="../../frame/layui/css/layui.css">
    <link rel="stylesheet" href="../../frame/static/css/style.css">
    <link rel="stylesheet" href="../../css/common.css">
    <style>
        .table-title{
            width: 1400px;
        }
        .table-title div{
            width: 10%;
            padding: 5px 10px;
        }
        .table-content td{
            padding: 2px 10px;
          	height:20px;
            line-height: 20px;
        }
        .td{
          	line-height:20px;
            width: 10%;
          	height:20px
            
        }
        .data-table{
            width: 1400px;
        }
    </style>
</head>
<body class="body">
<!-- 工具集 -->
<div class="my-btn-box">
    <span class="fl">
        <a class="layui-btn btn-add btn-default" id="btn-refresh" onclick="location.reload()"><i class="layui-icon">&#x1002;</i></a>
        <a class="layui-btn btn-add btn-default" id="btn-add">交易</a>
        <a class="layui-btn btn-add btn-default default" >初始资金：0</a>
      	<a class="layui-btn btn-add btn-default now" >当前资金：0</a>
      	<a class="layui-btn btn-add btn-default" id="reset">重置当前资金</a>
      	<a class="layui-btn btn-add btn-default" id="renum">重置当前持有量</a>
    </span>
</div>
<div class="my-btn-box" id="numcount">
    
</div>
<!-- 表格 -->
<div class="dateTable">
    <div class="table-title">
        <div>币种</div>
        <div>单价</div>
        <div>数量</div>
        <div>类型</div>
        <div>时间</div>
    </div>
    <table class="data-table" id="data-table">

    </table>
    <div id="pagebox">

    </div>
</div>
<script src="../../js/public/jquery-3.1.1.min.js"></script>
<script src="../../js/layer/layer.js"></script>
<script src="../../js/public/common.js"></script>
<script>
    $(function(){
        list();
        getMoney();
        $('#btn-add').click(function(){
            layOpen('交易','600px','400px','edit.html');
        })
      
      	$('#reset').click(function(){
        	layFirm('确认重置？','admin/ClMoneyReSet');
        })
      
      	$('#renum').click(function(){
        	layFirm('确认重置？','admin/ClNumReSet');
        })
      	
    });
	
  	function getMoney(){
    	let res = AjaxForm('admin/getclmoeny');
      	$('.default').text(res.default);
      	$('.now').text(res.now);
    
    }	
    function list(){
        let page = GetQueryString('page');
        if(!page)page= 1;
        let res = AjaxForm('admin/TranList?page='+page);
        let data = res.list;
        let html = '';
        for (let i=0;i<=data.length-1;i++){
            let type = '卖出'
            if(data[i].type == 2)type = '买入'
            html +=
                "<tr class=\"table-content\">\n" +
                "<td class='td'>"+data[i].title+"</td>" +
                "<td class='td'>"+data[i].price+"</td>" +
                "<td class='td'>"+data[i].num+"</td>" +
                "<td class='td'>"+type+"</td>" +
                "<td class='td'>"+formatDateTime(data[i].create_time)+"</td>" +
                "</tr>"
        }
        $('#data-table').html(html);      	
      	let num = ``;
      	for (let a=0;a<res.num.length;a++){ 
        	num += `<span class="fl" style="margin-right:15px"><a class="layui-btn btn-add btn-default">${res.num[a].title}:${res.num[a].num}</a></span>`
        }
      	console.log(res);
      	$('#numcount').html(num);
      	console.log(data)
        WepPage(res.count,page,'index');
    }
</script>
</body>
</html>